#include "myflower.h"
#include <QDebug>

//MyFlower::MyFlower(QWidget *parent) : PushButton(parent)
//{

//}

MyFlower::MyFlower(QString btnImg)
{
    QPixmap pix;
    bool ret = pix.load(btnImg);
    if(!ret)
    {
        QString str = QString("图片 %1 加载失败").arg(btnImg);
        qDebug()<<str;
        return;
    }

    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{boarder:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));

    timer1 = new QTimer(this);
    timer2 = new QTimer(this);

    connect(timer1,&QTimer::timeout,[=](){
        QPixmap pix;
        pix.load(":/pictures/red.png");

        this->setFixedSize(pix.width(),pix.height());
        this->setStyleSheet("QPushButton{boarder:0px;}");
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));

        IsAnimation = false;
        timer1->stop();
    });

    connect(timer2,&QTimer::timeout,[=](){
        QPixmap pix;
        pix.load(":/pictures/yellow.png");

        this->setFixedSize(pix.width(),pix.height());
        this->setStyleSheet("QPushButton{boarder:0px;}");
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));

        IsAnimation = false;
        timer2->stop();
    });
}

void MyFlower::changeFlag()
{
    if(this->flag)
    {
        IsAnimation = true;
        timer1->start(30);
        this->flag=false;
    }
    else
    {
        IsAnimation = true;
        timer2->start(30);
        this->flag=true;
    }
}
